home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: 100435.736@compuserve.com (David A. Mair)
- Newsgroups: comp.lang.c++
- Subject: Re: How do you return values from in-line asm?
- Date: Wed, 10 Apr 1996 09:36:07 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4kfvec$s6k@arl-news-svc-4.compuserve.com>
- References: <4j9mab$19si@usenetp1.news.prodigy.com>
- NNTP-Posting-Host: dd41-171.compuserve.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- XKWR65B@prodigy.com (Mark Rubelmann) wrote:
-
-
- Firstly, let me state for the record that this is not a C++ question
- and you should perhaps have posted it in an MS-DOS or Intel assembly
- language group. You question is really off the topic that this group
- deals with. However,...
-
- >First of all, I just don't understand how the resut went from al to ax.
-
- This is simple, al is part of ax. The ax register is 16 bits wide and
- al is a synonym for the low byte and ah is a synonym for the high
- byte. Therefore ax = ahal (if you see what I mean).
-
- >Also, I know the line labels should be outside of the asm statement but
- >that's the way it was in the book.
-
- The book was clearly wrong.
-
- > I've tried fooling around with ret and
- >stuff like that but I can't get it to work. The compiler always gives a
- >warning that it should return a value.
-
- The compiler operates on the source code provided and if you include
- an early return the compiler continues to compile until it finds the
- close brace matching the open brace after the declaration. If your
- function has a return type the compiler must see a:
-
- return <lvalue of return type>;
-
- Here's how I do this (using your code):
-
- unsigned char Get_Scan_Code(void)
- {
- unsigned char byRetVal = 0;
-
- asm {
- mov ah,01h //Function 1: is a key ready?
- int 16h // Call interrupt
- jz done // No key, exit *** byRetVal is already 0
- mov ah,00h // Function 0: get scan code
- int 16h // Call interrupt
- // Not required because we can move ah to the return var
- // mov al,ah // result was in ah so put it in al
- // xor ah,ah // zero out ah
-
- mov byte ptr [byRetVal], ah
-
- // Replaced by initialising return variable to zero
- // jmp done // the data's in ax (??? ax???)
- //
- //empty:
- // xor ax,ax // clear out ax, 0 means no key
- }
- done:
-
- return byRetVal;
- }
-
- >When I try to use the function in
- >something like:
-
- > while(Get_Scan_Code==0) {}
-
- >but it doesn't work, it just goes on to the next statement. Any help
- >would be appreciated.
-
- That's a little unusual, but I suspect your compiler uses ax or
- restores a value into it because you have not implied its use by
- including a return statement. Or, perhaps, your compiler pretends the
- function is void because it doesn't return a value and (void == 0) is
- false.
-
- Regards
- David.
-
-
-